import netifaces as ni #external
import cPickle
import json
import zlib


AF_INET=2
AF_INET6=10
AF_PACKET=17

def get_host_info():
	host_info={}
	for nf in ni.interfaces():
		if nf !="lo":
			host_info[nf]={}
			info=ni.ifaddresses(nf)
			host_info[nf]['mac']=info[AF_PACKET][0]['addr']
			host_info[nf]['bc']=info[AF_INET][0]['broadcast']
			host_info[nf]['nm']=info[AF_INET][0]['netmask']
			host_info[nf]['ip']=info[AF_INET][0]['addr']
	return host_info

class PolicyStore(object):
	"""docstring for policy_store"""
	def __init__(self,name):
		store_name=name
		pass

	def store_init(self):
		return cPickle.load(open(store_name))
		pass
	def store_update(self):
		pass

	def store_save(self):
		pass

def test():
	pass
		



if __name__ == '__main__':
	str1=json.dumps(get_host_info())
	print len(str1)
	print str1
	str2=zlib.compress(str1,zlib.Z_BEST_SPEED)
	print len(str2)
	#print str2
	str3=zlib.decompress(str2)
	print len(str3)
	print str3